export const state = () =>{
    //声明全局变量保存历史数据
    return{
        searchInfo:[],
        orderDetail:{},
        //声明机票人数
        pnum:1,
        //声明机票总价
        allPrice:"",
        singlePrice:"",
        airport_tax_audlet:"",
        insurance:[]
    }
}

//声明mutations(突变)函数用以更改全局变量的值
export const mutations={
    Set_searchInfo(state,data){
        state.searchInfo.push(data)
    },
    Clear_Record(state){
        console.log(14,"清空记录")
        state.searchInfo=[]
    },
    Set_OrderDetail(state,data){
        state.orderDetail=data
    },
    //vuex中不可以同时传递多个参数，只能通过数组或者对象传递
    Set_AllPrice(state,data){
        state.singlePrice=data[0]
        state.airport_tax_audlet=data[1]
        state.allPrice=state.singlePrice*state.pnum+state.airport_tax_audlet*state.pnum
        console.log("这是总价格",state.allPrice)
    },
    Add_Pnum(state){
        state.pnum++
        //重新设置总价
        state.allPrice=state.singlePrice*state.pnum+state.airport_tax_audlet*state.pnum
        for(let i = 0;i<state.insurance.length;i++){
            state.allPrice+=state.insurance[i]*state.pnum
        }
    },
    clear_Pnum(state){
        state.pnum=1
        state.insurance=[]
    },
    deletePnum(state){
        state.pnum--
        state.allPrice=state.singlePrice*state.pnum+state.airport_tax_audlet*state.pnum
    },
    addInsurance(state,iprice){
        state.allPrice+=iprice
    },
    deleteInsurance(state,iprice){
        state.allPrice-=iprice
    }
}